<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace="TProjectBasic" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<statements>

<sql id="sql_TProjectBasic_where_cv_x">
  <dynamic prepend="WHERE">
    <isPropertyAvailable property="PrjId" prepend="AND">prj_id=#PrjId#</isPropertyAvailable>
    <isPropertyAvailable property="PrjName" prepend="AND">prj_name LIKE concat('%', #PrjName#, '%')</isPropertyAvailable>
    <isPropertyAvailable property="PrjType" prepend="AND">prj_type=#PrjType#</isPropertyAvailable>
    <isPropertyAvailable property="PrjConsOrg" prepend="AND">prj_cons_org LIKE concat('%', #PrjConsOrg#, '%')</isPropertyAvailable>
    <isPropertyAvailable property="PrjRegion" prepend="AND">prj_region=#PrjRegion#</isPropertyAvailable>
    <isPropertyAvailable property="PrjApproveGov" prepend="AND">prj_approve_gov=#PrjApproveGov#</isPropertyAvailable>
    <isPropertyAvailable property="PrjIndustry" prepend="AND">prj_industry=#PrjIndustry#</isPropertyAvailable>
    <isPropertyAvailable property="PrjSource" prepend="AND">prj_source=#PrjSource#</isPropertyAvailable>
    <isPropertyAvailable property="PrjEngineer" prepend="AND">prj_engineer=#PrjEngineer#</isPropertyAvailable>
    <isPropertyAvailable property="PrjEngineerName" prepend="AND">prj_engineer_name LIKE concat('%', #PrjEngineerName#, '%')</isPropertyAvailable>
    <isPropertyAvailable property="PrjContact" prepend="AND">prj_contact LIKE concat('%', #PrjContact#, '%')</isPropertyAvailable>
    <isPropertyAvailable property="PrjContactTel" prepend="AND">prj_contact_tel LIKE concat('%', #PrjContactTel#, '%')</isPropertyAvailable>
    <isPropertyAvailable property="PrjCoopOrg" prepend="AND">prj_coop_org LIKE concat('%', #PrjCoopOrg#, '%')</isPropertyAvailable>
    <isPropertyAvailable property="PrjCoopFee" prepend="AND">prj_coop_fee=#PrjCoopFee#</isPropertyAvailable>
    <isPropertyAvailable property="PrjCost" prepend="AND">prj_cost=#PrjCost#</isPropertyAvailable>
    <isPropertyAvailable property="PrjDocNo" prepend="AND">prj_doc_no LIKE concat('%', #PrjDocNo#, '%')</isPropertyAvailable>
    <isPropertyAvailable property="PrjLeader" prepend="AND">prj_leader=#PrjLeader#</isPropertyAvailable>
    <isPropertyAvailable property="PrjLeaderName" prepend="AND">prj_leader_name LIKE concat('%', #PrjLeaderName#, '%')</isPropertyAvailable>
    <isPropertyAvailable property="PrjScheduled" prepend="AND">prj_scheduled=#PrjScheduled#</isPropertyAvailable>
    <isPropertyAvailable property="PrjScheduled_0" prepend="AND"><![CDATA[prj_scheduled>=#PrjScheduled_0#]]></isPropertyAvailable>
    <isPropertyAvailable property="PrjScheduled_1" prepend="AND"><![CDATA[prj_scheduled<=#PrjScheduled_1#]]></isPropertyAvailable>
    <isPropertyAvailable property="PrjBeginDate" prepend="AND">prj_begin_date=#PrjBeginDate#</isPropertyAvailable>
    <isPropertyAvailable property="PrjBeginDate_0" prepend="AND"><![CDATA[prj_begin_date>=#PrjBeginDate_0#]]></isPropertyAvailable>
    <isPropertyAvailable property="PrjBeginDate_1" prepend="AND"><![CDATA[prj_begin_date<=#PrjBeginDate_1#]]></isPropertyAvailable>
    <isPropertyAvailable property="Progress" prepend="AND">_progress=#Progress#</isPropertyAvailable>
    <isPropertyAvailable property="Contract" prepend="AND">_contract=#Contract#</isPropertyAvailable>
    <isPropertyAvailable property="Filed" prepend="AND">_filed=#Filed#</isPropertyAvailable>
    <isPropertyAvailable property="Invoice" prepend="AND">_invoice=#Invoice#</isPropertyAvailable>
    <isPropertyAvailable property="Receipt" prepend="AND">_receipt=#Receipt#</isPropertyAvailable>
    <isPropertyAvailable property="BonusApply" prepend="AND">_bonus_apply=#BonusApply#</isPropertyAvailable>
    <isPropertyAvailable property="Date" prepend="AND">_date=#Date#</isPropertyAvailable>
    <isPropertyAvailable property="Staff" prepend="AND">_staff=#Staff#</isPropertyAvailable>
    <isPropertyAvailable property="PrjContractSignedAs" prepend="AND">prj_id in (select st.prj_id from t_project_contract st where st.prj_id = prj_id and st.prj_contract_signed_as=#PrjContractSignedAs#)</isPropertyAvailable>
    <isPropertyAvailable property="XStaff" prepend="AND">
      (
      prj_leader=#XStaff# OR prj_engineer=#XStaff#
      OR prj_id in (select distinct st1.prj_id from r_project_member st1 where st1.prj_id = prj_id and st1.stf_id=#XStaff#)
      OR prj_id in (select distinct st2.prj_id from l_project_approve st2 where st2.prj_id = prj_id and (st2.step1_staff=#XStaff# OR st2.step3_staff=#XStaff#))
      )
    </isPropertyAvailable>
    <isPropertyAvailable property="XMember" prepend="AND">
      (prj_id in (select distinct st3.prj_id from r_project_member st3 where st3.prj_id = prj_id and st3.stf_id=#XMember#))
    </isPropertyAvailable>
    <isPropertyAvailable property="XApprover" prepend="AND">
      (prj_id in (select distinct st4.prj_id from l_project_approve st4 where st4.prj_id = prj_id and (st4.step1_staff=#XApprover# OR st4.step3_staff=#XApprover#))
    </isPropertyAvailable>
  </dynamic>
</sql>

<select id="SelectTProjectBasic_PC" parameterClass="System.Collections.IDictionary" resultClass="int">
SELECT COUNT(*)
FROM t_project_basic
<include refid="sql_TProjectBasic_where_cv_x"/>
</select>

<select id="SelectTProjectBasic_PG" parameterClass="System.Collections.IDictionary" resultMap="TProjectBasic.select-tprojectbasic-result">
SELECT *
FROM t_project_basic
<include refid="sql_TProjectBasic_where_cv_x"/> limit $_offset$,$_rows$
</select>
</statements>
</sqlMap>